package com.kingwang.training.designpattern.chainofresponsibility;

import com.kingwang.training.designpattern.chainofresponsibility.bo.DepartmentManager;
import com.kingwang.training.designpattern.chainofresponsibility.bo.GeneralManager;
import com.kingwang.training.designpattern.chainofresponsibility.bo.HrManager;
import com.kingwang.training.designpattern.chainofresponsibility.bo.LeaveApplication;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.time.LocalDateTime;

@SpringBootApplication
public class ChainOfResponsibilityApplication implements ApplicationRunner {

    public static void main(String[] args) {
        SpringApplication.run(ChainOfResponsibilityApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        DepartmentManager departmentManager = new DepartmentManager("老杨");
        HrManager hrManager = new HrManager("许姐");
        GeneralManager generalManager = new GeneralManager("刘总");

        departmentManager.setNextApprover(hrManager);
        hrManager.setNextApprover(generalManager);

        LeaveApplication application = new LeaveApplication("小张", 30d, LocalDateTime.now());

        departmentManager.handle(application);
    }
}
